package com.synnex.mobile.servier.web.notification.controller;

import com.synnex.mobile.generic.core.pager.DataResults;
import com.synnex.mobile.generic.core.pager.Pagination;
import com.synnex.mobile.servier.core.msgBoard.bo.criteria.MsgBoardCriteria;
import com.synnex.mobile.servier.core.notification.bo.NotificationBo;
import com.synnex.mobile.servier.core.notification.bo.criteria.NotificationCriteria;
import com.synnex.mobile.servier.core.notification.service.DeviceTokenService;
import com.synnex.mobile.servier.core.notification.service.NotificationService;
import com.synnex.mobile.servier.web.common.controller.AbstractController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author kerryf
 */
public abstract class AbstractNotifyController extends AbstractController {

    protected NotificationService notificationService;
    protected DeviceTokenService tokenService;

    public void setTokenService(DeviceTokenService tokenService) {
        this.tokenService = tokenService;
    }

    public void setNotificationService(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

    public Map<String,Object> getNotifications(HttpServletRequest request,String from) {

        String link = "http://"+this.getConfig().getFtpHost()+this.getConfig().getFtpDownLoadPath()+"/";
        NotificationCriteria criteria = new NotificationCriteria();
        Pagination pagination = createPagination(request);
        criteria.setPagination(pagination);
        DataResults<NotificationBo> results = notificationService.getNotification(criteria, from);

        Map model = new HashMap<String,Object>();
        model.put("link",link);
        model.put("totalCount", results.getTotalCount());
        model.put("pageNo", pagination.getPageNo());
        model.put("pageSize", pagination.getPageSize());
        model.put("results", results.getResults());
        model.put("dataWrap", results);
        return model;
    }
}
